package com.jlf.core.ngac.domain;

import com.jlf.core.ngac.domain.actor.ActorIdentity;
import com.jlf.core.ngac.domain.app.Application;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;

/**
 * 当前会话
 *
 * @author wujr
 * 2023/7/5
 * @version 1.0
 * 【变更历史】
 * [wujr 2023/7/5 1.0 新增]
 */
@Getter
@Setter
public class Session {
    /**
     * 登录id
     */
    private Long loginId;
    /**
     * 本次的请求时间
     */
    private Date time;
    /**
     * 本次请求的权限编码
     */
    private String permission;
    /**
     * 本次请求所发起的接入应用编码
     */
    private String appCode;
    /**
     * 本次请求的接口编码
     */
    private String apiCode;
    /**
     * 本次请求的业务编码
     */
    private String business;
    /**
     * 本次请求的算法
     */
    private String algorithm;
    /**
     * 令牌的有效期
     */
    private Date expire;
    /**
     * 当前请求用户
     */
    private ActorIdentity current;
    /**
     * 当前的应用
     */
    private Application application;

    public Long profileId(){
        if (current == null){
            return -1L;
        }
        return current.getProfileId();
    }
    public Long identityId(){
        if (current == null){
            return -1L;
        }
        return current.getId();
    }
    public String nickname(){
        if (current == null){
            return "unknown";
        }
        return current.getNickname();
    }
    public String applicationCode(){
        if (application == null){
            return "unknown";
        }
        return application.getCode();
    }
}
